home *** CD-ROM | disk | FTP | other *** search
- #include "patches.h"
- #include <traps.h>
- #include <lowmem.h>
-
- #include <iostream>
- #include <qdoffscreen.h>
- #include "RectUtilities.h"
- #include "flames.h"
-
- static asm long* GetOldDebugUtilStorage()
- {
- lea _oldDebugUtilStorage,a0
- rts
- _oldDebugUtilStorage:
- dc.l 0x00000000
- }
-
- static asm long* GetCountStorage()
- {
- lea _countStorage,a0
- rts
- _countStorage:
- dc.l 0x00000000
- }
-
-
- static asm long* GetValueStorage()
- {
- lea _valueStorage,a0
- rts
- _valueStorage:
- dc.l 0x00000000
- }
-
-
-
- static asm long* GetA5Storage()
- {
- lea _a5Storage,a0
- rts
- _a5Storage:
- dc.l 0x00000000
- }
-
-
-
- static Boolean KeyIsDown(
- short theKeyCode)
- {
- KeyMap theKeys;
-
- GetKeys( theKeys); /* Get state of each key */
-
- /* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a */
- /* 16-byte (128 bits) array where each bit specifies the start */
- /* of a key (0 = up, 1 = down). We isolate the bit for the */
- /* specified key code by first determining the byte position in */
- /* the KeyMap and then the bit position within that byte. */
- /* Key codes 0-7 are in the first byte (offset 0 from the */
- /* start), codes 8-15 are in the second, etc. The BitTst() trap */
- /* counts bits starting from the high-order bit of the byte. */
- /* For example, for key code 58 (the option key), we look at */
- /* the 8th byte (7 offset from the first byte) and the 5th bit */
- /* within that byte. */
-
- return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
- (long) 7 - (theKeyCode % 8) ) );
- }
-
- // 16777216
-
- static void memset(Ptr p,char value,long length)
- {
- long z = 0;
- for(z = 0;z<length;z++){
- p[z] = value;
- }
- }
-
- static Ptr GetScreenBase()
- {
- GDHandle h = LMGetMainDevice();
-
- return h[0]->gdPMap[0]->baseAddr;
- }
-
- static CGrafPort gMyPort;
- static FlameDataRecPtr gFlames = NULL;
- static long Poll(short selector)
- {
- long continueQ = true;
- long* myA5 = GetA5Storage();
-
- SetA5(*myA5);
-
- long* count = GetCountStorage();
-
- if(selector == 3){
- (*count)++;
-
- if( ((*count) % 150) == 0){
-
- if(gFlames)
- StepFlames(gFlames);
-
- }
- }
-
- return continueQ;
- }
-
-
- static asm void newDebugUtil()
- {
- subq.l #4,a7 // reserve space for old trap address
- move.l a0,-(a7) // save a0
- movem.l a1-a5/d0-d7,-(a7) // save everything else
-
- move.w d0,-(a7)
- jsr Poll
- addq.l #2,a7
- tst.w d0
- bne.s _Continue
-
- movem.l (a7)+,a1-a5/d0-d7
- move.l (a7)+,a0
- addq.l #4,a7
- rts
-
- _Continue:
-
-
- movem.l (a7)+,a1-a5/d0-d7 // restore registers
-
- jsr GetOldDebugUtilStorage // get original trap address storage in a0
- move.l (a0),a0 // get original trap address value into a0
- move.l a0,4(a7) // stuff old trap onto stack
- move.l (a7)+,a0 // restore original a0
- rts // rts to jump to old trap.
- }
-
- static void LockHandle(Handle h)
- {
- if(h){
- HLock(h);
- }
- }
-
- static void UnlockHandle(Handle h)
- {
- if(h){
- HUnlock(h);
- }
- }
-
- static void UnlockPixMap(PixMapHandle p)
- {
- if(p){
- UnlockHandle((Handle)p);
- UnlockHandle((Handle)p[0]->pmTable);
- }
- }
-
- static void LockPixMap(PixMapHandle p)
- {
- if(p){
- LockHandle((Handle)p);
- LockHandle((Handle)p[0]->pmTable);
- }
- }
-
- static void LockPixPat(PixPatHandle p)
- {
- if(p){
- LockHandle((Handle)p);
- LockPixMap(p[0]->patMap);
- LockHandle((Handle)p[0]->patData);
- LockHandle((Handle)p[0]->patXData);
- LockHandle((Handle)p[0]->patXMap);
- }
- }
-
- void main()
- {
- cout << "Init" << endl;
-
- GDHandle mainDevice = GetMainDevice();
-
- LockHandle((Handle)mainDevice);
- LockPixMap(mainDevice[0]->gdPMap);
- LockHandle((Handle)mainDevice[0]->gdITable);
- LockHandle((Handle)mainDevice[0]->gdSearchProc);
- LockHandle((Handle)mainDevice[0]->gdCompProc);
-
-
- OpenCPort(&gMyPort);
- SetPort((GrafPtr)&gMyPort);
- BackColor(blackColor);
- EraseRect(&gMyPort.portRect);
- BackColor(whiteColor);
-
- Rect macsBug;
- Rect screenRect;
- SetRect(&macsBug,0,0,640,480);
- SetRect(&screenRect,0,0,0x340,624);
- Point center;
-
- center.h = screenRect.right/2;
- center.v = screenRect.bottom/2;
-
- RectUtil::CenterRectOnPoint(&macsBug,center);
- RgnHandle screenRgn = NewRgn();
- RgnHandle mbRgn = NewRgn();
-
- RectRgn(screenRgn,&screenRect);
- RectRgn(mbRgn,&macsBug);
-
- DiffRgn(screenRgn,mbRgn,screenRgn);
-
- SetClip(screenRgn);
-
-
- LockPixMap(gMyPort.portPixMap);
- LockHandle((Handle)gMyPort.grafVars);
- LockHandle((Handle)gMyPort.visRgn);
- LockHandle((Handle)gMyPort.clipRgn);
- LockPixPat(gMyPort.bkPixPat);
- LockPixPat(gMyPort.pnPixPat);
- LockPixPat(gMyPort.fillPixPat);
-
-
- double fFadeRate = 0.04;
- double fDensity = 0.5;
- short fMinWidth = 2;
- short fMaxWidth = 4;
-
- FlameDataRecPtr f;
-
-
- Rect myRect;
-
- myRect = macsBug;
- myRect.bottom = myRect.top;
- myRect.top -= 75;
- myRect.left += 100;
- myRect.right -= 100;
-
- // myRect.top = myRect.bottom - 50;
- // myRect.right = myRect.left + 150;
- // myRect.top = myRect.bottom - 100;
- // myRect.left += 200;
- // myRect.right -= 200;
-
- f = MakeNewFlames ((GrafPtr)&gMyPort, &myRect,
- fMinWidth,fMaxWidth,
- fDensity, fFadeRate,
- 30,GetCTable(1280));
-
- LockFlames(f);
- StartFlames (f);
-
- gFlames = f;
-
-
- long* a5Storage = GetA5Storage();
- *a5Storage = SetCurrentA5();
-
- long* debugUtilStorage = GetOldDebugUtilStorage();
- *debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
-
-
- Debugger();
-
-
-
- FreeFlames(&f);
-
- CloseCPort(&gMyPort);
-
-
- UnlockHandle((Handle)mainDevice[0]->gdCompProc);
- UnlockHandle((Handle)mainDevice[0]->gdSearchProc);
- UnlockHandle((Handle)mainDevice[0]->gdITable);
- UnlockPixMap(mainDevice[0]->gdPMap);
- UnlockHandle((Handle)mainDevice);
-
- }
-
- /*
- void main()
- {
- cout << "init" << endl;
-
- GWorldPtr myGWorld;
- Rect myBounds;
- SetRect(&myBounds,0,0,0x340,624);
- OSErr err = NewGWorld(&myGWorld, 8, &myBounds, NULL,NULL, 0);
- if(err == noErr){
- LockPixels(GetGWorldPixMap(myGWorld));
- HLock((Handle)GetGWorldPixMap(myGWorld));
-
- // long* a5Storage = GetA5Storage();
- // *a5Storage = SetCurrentA5();
-
- // long* debugUtilStorage = GetOldDebugUtilStorage();
- // *debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
-
- DPGlobals* dpGlobals = GetDPGlobalStorage();
- InitDPGlobals(dpGlobals);
- Ptr screenBase = GetScreenBase();
- long* value = GetValueStorage();
-
- dpGlobals->gDPAddress = GetGWorldPixMap(myGWorld)[0]->baseAddr;
- dpGlobals->gDPBytesPerRow = GetGWorldPixMap(myGWorld)[0]->rowBytes;
- dpGlobals->gDPHeight = 624;
- dpGlobals->gDPWidth = 0x0340;
- dpGlobals->gDPDepth = 8;
-
- const UInt32 kScreenWidth = 0x0340;
- const UInt32 kScreenHeight = 624;
-
- *value = !(*value);
- DPFilledRect (dpGlobals,0, 0, kScreenWidth, kScreenHeight, (*value)?0:0xFF);
- CopyBits((BitMap*)*GetGWorldPixMap(myGWorld), (BitMap*)*GetMainDevice()[0]->gdPMap, &myBounds, &myBounds, 0,NULL);
-
- Debugger();
- // *value = !(*value);
- // DPMoveTo(dpGlobals,0,0);
- // DPLineTo(dpGlobals,400,0,1);
- // Debugger();
- // DPMoveTo(dpGlobals,0,0);
- // DPLineTo(dpGlobals,400,0,50);
- // Debugger();
- // Debugger();
- }
-
- }
-
- */